$(document).ready(function(){
		$("#role-select-object").click(function(){
			if($(this).attr("checked")) {
				$("input[type='checkbox'][name*='role_']").each(function(n){
					if (!$(this).attr("checked")) {
						 $(this).attr("checked","checked");
					}
				});
			} else {
				$("input[type='checkbox'][name*='role_']").each(function(n){
					if ($(this).attr("checked")) {
						 $(this).attr("checked",false);
					}
				});
			}
		});
		$("#role-batch-del").click(function(){
			var ids = new Array();
			var i = 0;
			$("input[type='checkbox'][name*='role_']").each(function(n){
				if ($(this).attr("checked")) {
					ids[i++]=$(this).attr("value");
				}
			});
			if (ids.length == 0) {
				alert("请选择要删除的记录");
				return;
			}
			var formStr = "<form action='role!del.action' method='post' id='roleDelForm'><input type='hidden' name='ids' value='"+ids.toString()+"'/></form>";
			$("#roleDelDiv").empty();
			$("#roleDelDiv").append(formStr);
			$("#roleDelForm").submit();
			
		});
		$("#role-add").click(function(){
			var url = "role!showAdd.action";
			document.location.href =  url;
		});
});
function roleAdd() {
	    var ids = new Array();
	    var j = 0;
	    $("select[id='rightPriSelect'] option").each(function(){ 
    	     ids[j++] = $(this).val();
	    }); 
	    $("#privilegeIds").val(ids.toString());
	    $("#roleAddForm").submit();
}
function roleSet(id) {
    var ids = new Array();
    var j = 0;
    $("select[id='rightPriSelect'] option").each(function(){ 
	     ids[j++] = $(this).val();
    }); 
    $("#privilegeIds").val(ids.toString());
    $("#roleSetForm").submit();
}
function roleOneDel(id) {
	var formStr = "<form action='role!del.action' method='post' id='roleDelForm'><input type='hidden' name='ids' value='"+id+"'/></form>";
	$("#roleDelDiv").append(formStr);
	$("#roleDelForm").submit();
}

//角色赋权操作 leftPriSelect  rightPriSelect
function moveOneRight() {

    $("#leftPriSelect option:selected").appendTo("#rightPriSelect");

	$("select[id='rightPriSelect'] option").each(function(){
		  if($(this).attr("selected")){
			  $(this).attr("selected", false);
		  }
	});
}
function moveAllRight() {
	$("select[id='leftPriSelect'] option").each(function(){
		$(this).appendTo("#rightPriSelect");
	});
}
function moveOneLeft() {
	 $("#rightPriSelect option:selected").appendTo("#leftPriSelect");

		$("select[id='leftPriSelect'] option").each(function(){
			  if($(this).attr("selected")){
				  $(this).attr("selected", false);
			  }
		});
}
function moveAllLeft() {
	$("select[id='rightPriSelect'] option").each(function(){
		$(this).appendTo("#leftPriSelect");
	});
}

